#!/usr/bin/env python
# coding: utf-8
# $Id: ex3consumer.py 9 2009-04-27 16:54:05Z fiorix $
# delayed square calculator, consumer

import parallels
from twisted.internet import defer, reactor

def square(n, deferred):
    deferred.callback(n*n)

class consumer(parallels.ConsumerProtocol):
    def get(self, item):
	# Here I simply defer the execution of the
	# square() method using reactor.callLater()
	deferred = defer.Deferred()
	reactor.callLater(1, square, item, deferred)
	return deferred

if __name__ == '__main__':
    consumer(runReactor=True)
